package com.wzq.design.business.system.menu.controller;

import com.wzq.design.base.controller.CommController;
import com.wzq.design.base.dto.QueryByIdRequest;
import com.wzq.design.base.dto.RemoveRequest;
import com.wzq.design.business.system.menu.dto.RouteDto;
import com.wzq.design.business.system.menu.dto.SysMenuDto;
import com.wzq.design.business.system.menu.service.MenuService;
import com.wzq.ssm.parent.base.dto.JsonResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author wangzhiqiang
 * @since 2023/5/8 15:07
 */
@RestController
@RequestMapping("/sys/menu")
public class MenuController extends CommController {
    private final MenuService menuService;

    public MenuController(MenuService menuService) {
        this.menuService = menuService;
    }


    @GetMapping("/list")
    public JsonResult<List<SysMenuDto>> list() {
        return JsonResult.success("查询成功", menuService.list());
    }

    @GetMapping("/listTree")
    public JsonResult<List<SysMenuDto>> listTree() {
        return JsonResult.success("查询成功", menuService.listTree());
    }

    @PostMapping("/delete")
    public JsonResult<?> delete(@RequestBody RemoveRequest request) {
        menuService.deleteByIds(request.getIds());
        return JsonResult.success("删除成功");
    }

    @PostMapping("/save")
    public JsonResult<SysMenuDto> save(@RequestBody SysMenuDto request) {
        return JsonResult.success("保存成功", menuService.save(request));
    }


    @GetMapping("/findById")
    public JsonResult<SysMenuDto> findById(QueryByIdRequest request) {
        return JsonResult.success("保存成功", menuService.findById(request));
    }

    @GetMapping("/routes")
    public JsonResult<List<RouteDto>> getMenuTree(){
        return JsonResult.success("",menuService.getMenuTree());
    }
}
